package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.WxDriverRecord;
import com.ruoyi.system.service.IWxDriverRecordService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * recordController
 * 
 * @author ruoyi
 * @date 2021-07-27
 */
@Controller
@RequestMapping("/system/record")
public class WxDriverRecordController extends BaseController
{
    private String prefix = "system/record";

    @Autowired
    private IWxDriverRecordService wxDriverRecordService;

    @RequiresPermissions("system:record:view")
    @GetMapping()
    public String record()
    {
        return prefix + "/record";
    }

    /**
     * 查询record列表
     */
    @RequiresPermissions("system:record:list")
    @RequestMapping("/list")
    @ResponseBody
    public TableDataInfo list(WxDriverRecord wxDriverRecord)
    {
        startPage();
        List<WxDriverRecord> list = wxDriverRecordService.selectWxDriverRecordList(wxDriverRecord);
        return getDataTable(list);
    }

    /**
     * 导出record列表
     */
    @RequiresPermissions("system:record:export")
    @Log(title = "record", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WxDriverRecord wxDriverRecord)
    {
        List<WxDriverRecord> list = wxDriverRecordService.selectWxDriverRecordList(wxDriverRecord);
        ExcelUtil<WxDriverRecord> util = new ExcelUtil<WxDriverRecord>(WxDriverRecord.class);
        return util.exportExcel(list, "record数据");
    }

    /**
     * 新增record
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存record
     */
    @RequiresPermissions("system:record:add")
    @Log(title = "record", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WxDriverRecord wxDriverRecord)
    {
        return toAjax(wxDriverRecordService.insertWxDriverRecord(wxDriverRecord));
    }

    /**
     * 修改record
     */
    @GetMapping("/edit/{recordId}")
    public String edit(@PathVariable("recordId") Long recordId, ModelMap mmap)
    {
        WxDriverRecord wxDriverRecord = wxDriverRecordService.selectWxDriverRecordById(recordId);
        mmap.put("wxDriverRecord", wxDriverRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存record
     */
    @RequiresPermissions("system:record:edit")
    @Log(title = "record", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WxDriverRecord wxDriverRecord)
    {
        return toAjax(wxDriverRecordService.updateWxDriverRecord(wxDriverRecord));
    }

    /**
     * 删除record
     */
    @RequiresPermissions("system:record:remove")
    @Log(title = "record", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wxDriverRecordService.deleteWxDriverRecordByIds(ids));
    }
}
